//
//  SetupInformationViewController.m
//  smarthings
//
//  Created by Stefan Tsvyatkov on 10/26/14.
//  Copyright (c) 2014 Stefan Tsvyatkov. All rights reserved.
//

#import "SetupInformationViewController.h"

@implementation SetupInformationViewController

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 3;
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
    if (section == 0) {
        return @"Thing";
    }
    else if (section == 1 && self.thing.properties.count > 0) {
        return @"Properties";
    }
    else if (section == 2 && self.thing.actions.count > 0) {
        return @"Actions";
    }
    return nil;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (section == 0) {
        return 1;
    }
    else if (section == 1) {
        return self.thing.properties.count;
    }
    else if (section == 2) {
        return self.thing.actions.count;
    }
    return 0;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SetupInfoCell"];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"SetupInfoCell"];
    }
    
    if (indexPath.section == 0) {
        cell.textLabel.text = self.thing.name;
        cell.detailTextLabel.text = [NSString stringWithFormat:@"%@%@", [Smarthings baseServerURL], self.thing.href];
    }
    else if (indexPath.section == 1) {
        cell.textLabel.text = [self.thing.properties[indexPath.row] name];
        cell.detailTextLabel.text = [NSString stringWithFormat:@"%@%@", [Smarthings baseServerURL], [self.thing.properties[indexPath.row] href]];
    }
    else if (indexPath.section == 2) {
        cell.textLabel.text = [self.thing.actions[indexPath.row] name];
        cell.detailTextLabel.text = [NSString stringWithFormat:@"%@%@", [Smarthings baseServerURL], [self.thing.actions[indexPath.row] href]];
    }
    
    return cell;
}

@end
